//
//  HMToolBar.swift
//  weibo28
//
//  Created by 范英强 on 16/3/25.
//  Copyright © 2016年 范英强. All rights reserved.
//

import UIKit

class HMToolBar: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
         setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        backgroundColor = RandomColor()
        // 01- 控件的添加
        let retweetButton = addButton("timeline_icon_retweet", title: "转发")
        let commentButton = addButton("timeline_icon_comment", title: "评论")
        let unlikeButton = addButton("timeline_icon_unlike", title: "赞")
        let sp1 = addLine()
        let sp2 = addLine()
        
        // 02- 给控件添加约束
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(retweetButton.snp_trailing)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
            make.trailing.equalTo(self)
            make.bottom.equalTo(self)
        }
        
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)
        }

    }
    // 添加竖线
    func addLine() -> UIView{
        let line = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(line)
        return line
    }
    
    
    // 添加按钮
    func addButton(imgName: String,title: String) -> UIButton{
        //timeline_icon_retweet
        
        let button = UIButton()
        // 设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        // 设施image
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        // 设置文字
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        addSubview(button)
        return button
    }
    
    

    
    
    
}
